<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <title>Document</title>
</head>
<body>
<div id="app">
    <h2>爱好</h2>
    <ul>
        <li v-for="(item,index) in student.hobby" :key="index">
            {{item}}
        </li>
    </ul>
    <h2>朋友们</h2>
    <ul>
        <li v-for="(item,index) in student.friends" :key="index">
            {{item.name}}--{{item.age}}
        </li>
    </ul>

</div>
<script>
    const vm = new Vue({
        el:'#app',
        data:{
            student:{
                name:'彭于晏',
                age:18,
                hobby:['健身','打球'],
                friends:[
                    {name:'胡歌',age:19},
                    {name:'刘亦菲',age:20}
                ]
            }
        },
        methods: {
            add(){
                // Vue.set(this.student,'sex','男')
                // this.$set(this.student,'sex','男')
                // * 只允许给data里的某一个对象追加属性，不允许给data追加属性
                // 即：vm，vm的根数据对象都不允许作为target
                Vue.set(vm._data , "hobby" , "听音乐")
                console.log(vm._data)
            }
        }
    })
</script>
</body>

</html>


